﻿using Enums;
using Model.Entity;
using Model.Request;
using Model.Response;
using TemplateInterfaceDao;
using TemplateInterfaceService;
using Untils;

namespace TemplateService
{
    /// <summary>
    /// 用户服务
    /// </summary>
    public class UserService : IUserService
    {        
        private readonly IUsersDao _usersDao;
        
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="usersDao"></param>
        public UserService(IUsersDao usersDao)
        {            
            _usersDao = usersDao;
        }

        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public async Task<Users> GetUser(LoginRequest req)
        {
            return await _usersDao.GetUser(req.UserName, req.Password);
        }

        /// <summary>
        /// 根据查询条件获取用户列表
        /// </summary>
        /// <param name="req">查询条件</param>
        /// <returns></returns>
        public async Task<GetSearchUsersResponse> GetSearchUsers(GetSearchUsersRequest req)
        {
            (var result, var totalNumber) = await _usersDao.GetSearchUsers(req);
            GetSearchUsersBody body = new GetSearchUsersBody() 
            {
                searches = result,
                Total = totalNumber,
                PageNum = req.PageNum,
                PageSize = req.PageSize
            };
           
            return ApiResponseHelper.SucessMessage<GetSearchUsersBody, GetSearchUsersResponse>(ApiResponseHelper.GetDescription(SystemCode.SUCCESS), body);
        }
    }
}
